//
//  ViewController.swift
//  CHSimpleUI
//
//  Created by cyptt on 2022/5/31.
//

import UIKit
import SnapKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    var string:String?
   lazy var tableView = {()-> UITableView in
        let tabV = UITableView.init()
        tabV.delegate = self
        tabV.dataSource = self
        return tabV
    }()
    
    lazy var dataSourceArr = {()-> [String] in
        
        let dataArr = ["图片裁剪","OC","ToolS","Other","ViewPage","SigleButton","Alert","Button","ButtonListView","预览图片","progressView","Charts","tableview","menu","KEYBOARD","Signatrue","tab全选","mysqlite3","GridView","MVVMBase","ListView","CHLabel"]
        return dataArr
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.width.height.equalTo(self.view)
        }
    
        
        self.tabBarItem.badgeValue = "10"
        
        self.tabBarItem.badgeValue = nil
    }


    
}


extension ViewController{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSourceArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell:UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: "CELLID")
        if cell == nil{
            cell = UITableViewCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: "CELLID")
        }
        cell?.textLabel?.text = self.dataSourceArr[indexPath.row] as! String
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let title:String = self.dataSourceArr[indexPath.row]
        if title == "Alert" {
            print("alert")
            let vc:CHAlertVController = CHAlertVController.init()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "预览图片"){
            let vc:PreviewImageController = PreviewImageController.init()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "progressView"){
            let vc:CHProgressViewController = CHProgressViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if (title == "Charts"){
            let vc:ChartsViewController = ChartsViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "tableview"){
            let vc:CHTableViewController = CHTableViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if (title == "Button"){
            let vc:ButtonViewController = ButtonViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if(title == "menu"){
            let vc:CHMenuController = CHMenuController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "KEYBOARD"){
            let vc:KeyboradController = KeyboradController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if(title == "ToolS"){
            let vc:DefaultToolViewController = DefaultToolViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "Signatrue"){
            let vc:SignatrueViewController = SignatrueViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "tab全选"){
            let vc:TableViewSelectAllController = TableViewSelectAllController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if(title == "mysqlite3"){
            
            let vc:Sqlite3ViewController = Sqlite3ViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if title == "OC"{
            let vc:CHOcViewController = CHOcViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if title == "GridView"{
            let vc:CHGrideViewController = CHGrideViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if title == "MVVMBase"{
            let vc:MVVMBaseViewController = MVVMBaseViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if title == "Other"{
            let vc:OtherViewController = OtherViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if title == "ListView"{
            let vc:CHSimpleListViewController = CHSimpleListViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if title == "CHLabel"{
            let vc:CHLabelViewController = CHLabelViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            
        }else if title == "SigleButton"{
            let vc:SigleButtonViewController = SigleButtonViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if title == "ViewPage"{
            let vc:ViewPageViewController = ViewPageViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if title == "ButtonListView"{
            
            let vc:BottomListViewController = BottomListViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }else if title == "图片裁剪"{
           
            CHSysCamera.shared.openAblum(controller: self) { image, fileUrl in
                let cropVC = CHPhotoCropViewController(originalImage: image) { cropImage, fileUrl in
                    
                }failB: { failmsg in
                
                }
               
                
                self.present(cropVC, animated: true)
            } failB: { failmsg in
                
            }

        }
    }
    
    /**
     获取类名
     */
    func getClassName(_ aClass: AnyClass) -> String {
        
        let classN: String =  NSStringFromClass(aClass )
        
       let arr:[String] = classN.components(separatedBy: ".")
      
       let lastClassName:String = arr.last ?? "";
        return lastClassName
      
    }
}



